<cfsetting enablecfoutputonly="true">
<!--- @@displayname: Display latest cfugwa RSS agregator items --->

<cfimport taglib="/farcry/core/tags/webskin" prefix="skin" />

<!--- <cfset o = createObject("component",application.types['cfugwarss'].typepath)>
<cfset qRecordSet = queryNew("objectID") />
<cfset lCategoryObjectIDs = "" />
<cfset qObjectsMatchingCategories = queryNew("objectID") />

<cfif listLen(stObj.Category)>
	<cfset qObjectsMatchingCategories = createObject("component","farcry.core.packages.farcry.category").getData(typename="cfugwarss", lCategoryids=stobj.Category) />
	<cfset lCategoryObjectIDs = valueList(qObjectsMatchingCategories.objectid) />
</cfif>		

<cfset qRecordSet = o.getMultipleByQuery(maxRows=stObj.numItems, OrderBy="title", sortOrder="desc", lObjectIDs="#lCategoryObjectIDs#") />
 --->
<cftry>
	<cfset oRSS = createObject("component",application.types['cfugwarss'].typepath)>
	<cfset stAllRSS = oRSS.GETMULTIPLE() />
	<cfloop collection="#stAllRSS#" item="rssID">
		<cfset stRSS = oRSS.getData(rssID)>
	</cfloop>
<cfcatch >
	<!--- get over it --->
</cfcatch>
</cftry>

<cftry>
	
<!--- remove failed feeds --->

<cfset cfugwaRSS = StructNew() />
<cfdump var="#APPLICATION.STPLUGINS.cfugwaRSS#" label="start"  expand="false">
<cfloop collection="#APPLICATION.STPLUGINS.cfugwaRSS#" item="rssID">
	<cfset thisRSS  = APPLICATION.STPLUGINS.cfugwaRSS['#rssID#']>
	<cfdump var="#thisRSS#" label="thisRSS #rssID#" expand="false">
	<cfif NOT StructKeyExists(thisRSS, 'qryFeed')>
		<cfdump var="#thisRSS.qryFeed#" label="thisRSS.qryFeed" expand="false">
		<cfset cfugwaRSS['#rssID#'] = StructNew() />
		<cfset StructAppend(cfugwaRSS, thisRSS) />
	</cfif>
</cfloop>
<cfdump var="#cfugwaRSS#" label="end" expand="false">
<cfset i = 1 />
<cfset qryFeeds = QueryNew('title, PUBLISHEDDATE, sortTS, AUTHORNAME, CONTENT, rssTitle,RSSLINK') />
<cfset rssCount = StructCount(cfugwaRSS) />
<cfif rssCount GT 0>

<cfquery dbtype="query" name="qryFeeds" cachedwithin="#createtimespan(0, 1, 0, 0)#">
(<cfloop collection="#cfugwaRSS#" item="rssID">
	<cfset thisRSS  = cfugwaRSS['#rssID#']>
	<cfset theQuery = thisRSS.QRYFEED />
	
	<cfif not ListFindNoCase(theQuery.ColumnList, 'rssTitle')>
	
		<cfset rssTitle = thisRSS.STPROPERTIES.title />
		
		<cfset rssTitleArray = ArrayNew(1) />
		<cfset ArraySet(rssTitleArray,1,theQuery.RecordCount,rssTitle) />
		<cfset QueryAddColumn(theQuery, 'rssTitle','VarChar', rssTitleArray) />
		
		<cfset rssSortArray = ArrayNew(1) />
		<cfloop query="theQuery">
			<cfset ArrayAppend(rssSortArray, parseDateTime(theQuery.publishedDate)) />
		</cfloop>
		<cfset QueryAddColumn(theQuery,"sortTS","DATE",rssSortArray)>
	</cfif>
	
	<cfset "thisQuery#i#" = theQuery />
	SELECT title, PUBLISHEDDATE, sortTS, AUTHORNAME, CONTENT, rssTitle,RSSLINK
	FROM thisQuery#i#
	WHERE sortTS  > <cfqueryparam value="#DateAdd('d', -28, Now())#" cfsqltype="CF_SQL_DATE">

	<cfif i NEQ rssCount>UNION</cfif>
	<cfset i++ />

</cfloop>)
	ORDER BY sortTS DESC

</cfquery>
</cfif>
<cfcatch>
	<!--- <cfdump var="#cfugwaRSS#" label="cfugwaRSS">
	<cfdump var="#stAllRSS#" label="stAllRSS">
	<cfdump var="#thisRSS#" label="thisRSS"> --->
	<cfdump var="#cfcatch#" label="error">

	<cfabort />
</cfcatch>
</cftry>
<!--- IS THERE INTRO TEXT SET? --->
<cfif len(stObj.teaser)>		
	<cfset arrayAppend(request.aInvocations,stObj.teaser) />			
</cfif>

<cfoutput query="qryFeeds">
	<div class="post">
	<h3>#qryFeeds.TITLE#</h3>
	<p class="date">#DateFormat(qryFeeds.PUBLISHEDDATE, "mmmm dd,  yyyy")#<br />#qryFeeds.rssTitle#</p>
	<p>#qryFeeds.CONTENT#</p>
	<p><a href="#qryFeeds.RSSLINK#" target="_blank">more..</a>
<!--- 		<skin:buildLink objectid="#stobj.objectID#" >more...</skin:buildLink> ---></p>
	</div>
</cfoutput>


<!--- <cfdump var="#APPLICATION.STPLUGINS.cfugwaRSS#" expand="false">
<cfdump var="#qryFeeds#" label="qryFeeds" expand="false"> --->
<cfsetting enablecfoutputonly="false">


<cffeed action="read" query="qryFeed" properties="stProperties" source="#stobj.URL#" userAgent="cfugwa.com"  timeout="20" >
[2:20:15 PM] Matthew J Bryant says: <skin:view objectid="#stobj.objectid#" typename="ruleLatestCFUGWARSS" webskin="displayFeedItem"  feedTitle="#qryFeed.title#" feedContent="#qryFeed.content#" />
[2:23:47 PM] Matthew J Bryant says: feedItem
[2:24:06 PM] Matthew J Bryant says: <cfoutput>#stparam.feedTitle#</cfoutput